package com.sxz.sbs.module.client;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import com.sxz.sbs.R;
import com.sxz.sbs.applibrary.component.ClearEditText;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.base.BasePresenter;

import butterknife.BindView;

/**
 * @author hp
 * @date 2018/1/25
 * 客户搜索界面
 */

public class ClientSearchActivity extends BaseActivity{

    @BindView(R.id.cet_search_client)
    ClearEditText edSearchClient;
    @BindView(R.id.tv_search)
    TextView tvSearch;

    private String strSearchClient;

    @Override
    protected void init() {
        edSearchClient.addTextChangedListener(watcher);
        edSearchClient.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH){
                    Intent data = new Intent();
                    data.putExtra("strSearch", strSearchClient);
                    setResult(RESULT_OK, data);
                    finish();
                    return true;
                }
                return false;
            }
        });
        tvSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private TextWatcher watcher = new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
        }
        @Override
        public void afterTextChanged(Editable s) {
            strSearchClient=edSearchClient.getText().toString();
        }
    };

    @Override
    protected int getLayoutId() {
        return R.layout.activity_clientsearch;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}
